package com.oldwine.user.controller;

import com.oldwine.user.config.PatternProperties;
import com.oldwine.user.pojo.User;
import com.oldwine.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private PatternProperties properties;

    /**
     * 根据用户id查询用户信息
     * get请求  请求路径 /user/id
     *
     * @param userId 用户id
     * @return 返回User对象
     */
    @GetMapping("/{userId}")
    public User findUserById(@PathVariable("userId") Long userId) {
        return userService.findUserById(userId);
    }

    /**
     * 测试配置的热更新
     * @return 返回String类型字符串
     */
    @GetMapping("/test")
    public String test() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(properties.getDateformat()));
    }
}
